package com.nf.xiaomi.dao.impl;

import com.nf.dbutils.SqlExecutor;
import com.nf.dbutils.handlers.KeyedMapHandler;
import com.nf.dbutils.handlers.ScalarHandler;
import com.nf.xiaomi.dao.AttributeDao;
import com.nf.xiaomi.util.SqlExecutorUtils;

import java.math.BigInteger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public class AttributeDaoImpl implements AttributeDao {
    SqlExecutor executor = SqlExecutorUtils.getExecutor();
    @Override
    public Map<Integer, Map<String, Object>> getAttributeMap() {
        String sql="select attribute_id,attribute_list from attribute";
        SqlExecutor executor = SqlExecutorUtils.getExecutor();
        Map<Integer, Map<String, Object>> resultMap = executor.query(sql, new KeyedMapHandler<Integer>());
        return resultMap;
    }

    @Override
    public BigInteger insertAttribute(String attribute) {
        String sql="insert into attribute(attribute_list) values(?)";
        return executor.insert(sql, new ScalarHandler(), attribute);
    }
}
